<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

require dirname(__FILE__).'/pc_controller.php';

require_once dirname(__FILE__).'/menu.php';

class Volvo_customer extends PC_controller {

    public function __construct(){
        parent::__construct();
        $this->load->model('Volvocustomermodel','m_customer');
    }

    public function index(){
        $data = parent::index();

        $this->load->view('admin/volvo_customer',$data);
    }

    public function getCustomerList(){
        $assist['where'] = getFilter($this->input->post(),Volvocustomermodel::$searchField);
        $assist['like'] = getFilter($this->input->post(),Volvocustomermodel::$likeField);
        $assist['sort'] = getSort($this->input->post(),Volvocustomermodel::$sortField);
        $assist['pagination'] = getPagination($this->input->post());

        list($list,$count) = $this->m_customer->getCustomerListSection($assist);

        $this->response->setSuccess();
        $this->response->setItems($list);
        $this->response->setTotalCount($count);
        $this->response->responseExit();
    }

    public function exportCustomerList() {
        @set_time_limit(0);
        @ini_set('memory_limit', '2048M');


        $assist['where'] = getFilter($this->input->get(),Volvocustomermodel::$searchField);
        $assist['like'] = getFilter($this->input->get(),Volvocustomermodel::$likeField);
        $assist['sort'] = getSort($this->input->get(),Volvocustomermodel::$sortField);

        $this->load->library('excel');
        $this->excel->init('沃尔沃用户_'.date('YmdH').'.xls');
        $this->excel->addSheet('沃尔沃用户');
        $this->excel->addTitle(array(
            array('content'=>'ID'),
            array('content'=>'姓名'),
            array('content'=>'手机号'),
            array('content'=>'性别'),
            array('content'=>'省份'),
            array('content'=>'城市'),
            array('content'=>'经销商'),
            array('content'=>'创建时间'),
        ));
        
        list($list,$count) = $this->m_customer->getCustomerListSection($assist);


        global $g_hd_game_gift;

        $sex_array = array(
            0 => '未知',
            1 => '男',
            2 => '女',
        );
        foreach ($list as $key => $value) {
            $gift_info = array();

            $this->excel->addRow(array(
                array('content' => $value['customer_id']),
                array('content' => $value['customer_name']),
                array('content' => $value['customer_phone']),
                array('content' => $sex_array[$value['customer_sex']]),
                array('content' => $value['customer_province']),
                array('content' => $value['customer_city']),
                array('content' => $value['customer_shop']),
                array('content' => $value['customer_time_create']),
            ));
        }

        $this->excel->freezePanes(1,0);
        $this->excel->generate();
    }
}
/* End of file customer.php */
/* Location: ./application/controllers/customer.php */